package com.xk._03真题骗._03栈_队列;

/*
 * @description: https://leetcode.cn/problems/min-stack/
 * @author: xu
 * @date: 2022/10/30 7:34
 */
public class _155最小栈2 {
    private Node head;

    public _155最小栈2() {
        head = new Node(0, Integer.MAX_VALUE, null);
    }

    public void push(int val) {
        int min = head.min;
        head = new Node(val, Math.min(min, val), head);
    }

    public void pop() {
        head = head.next;
    }

    public int top() {
        return head.val;
    }

    public int getMin() {
        return head.min;
    }

    private static class Node{
        int val;
        int min;
        Node next;
        public Node(int val, int min, Node next) {
            this.val = val;
            this.min = min;
            this.next = next;
        }
    }
}
